<!DOCTYPE HTML>
<html>
  <head>
    <title>file upload</title>
    <meta charset="utf-8">
  </head>
   
  <body>
  	<style>
  	.model{
  		margin:10px ;
  		padding:10px ;
  		border:1px solid #ddd;
  	}
  	</style>
  	<div class = "model">
  	登录
	<input type="text" id="userName" name="xxx">
	<input type="password" id="password" name="xxx">
	<input type="button" id="button" value="submit">
  	</div>
  	
	<div class = "model">
	获取当前登录用户信息
	<input type="button" id="getUserBtn" value="getUser">
	</div>
	<div class = "model">
	当前用户权限检测
	<input type="text" id="checkPermissionUri" value="">
	<input type="button" id="checkPermissionBtn" value="checkPermission">
	</div>
	<div class = "model">
	退出登录
	<input type="button" id="logoutBtn" value="logout">
	</div>
	<div id="msg"></div>
	<script type="text/javascript">
	var contextPath = "/rest/sso";
	button.onclick = function(){
		var req = new XMLHttpRequest();
		msg.innerHTML = "...";
		req.open("POST", contextPath+"/login");
		req.setRequestHeader("Content-Type","application/json; charSet=UTF-8");
		req.onreadystatechange = function(){
		   if(this.readyState == 4){
				msg.innerHTML = this.response;
		   }
		}
		req.send(JSON.stringify({"userName":userName.value,"password":password.value}));
	}
	getUserBtn.onclick = function(){
		msg.innerHTML = "...";
		var req = new XMLHttpRequest();
		req.open("GET", contextPath+"/login");
		req.onreadystatechange = function(){
		   if(this.readyState == 4){
		     msg.innerHTML = this.response;
		   }
		}
		req.send();
	}
	checkPermissionBtn.onclick = function(){
		msg.innerHTML = "...";
		var req = new XMLHttpRequest();
		req.open("GET", contextPath+"/login/checkPermission?uri="+checkPermissionUri.value);
		req.onreadystatechange = function(){
		   if(this.readyState == 4){
		     msg.innerHTML = this.response;
		   }
		}
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset-UTF-8');
		req.send();
	}
	logoutBtn.onclick = function(){
		msg.innerHTML = "...";
		var req = new XMLHttpRequest();
		req.open("DELETE", contextPath+"/login");
		req.onreadystatechange = function(){
		   if(this.readyState == 4){
		     msg.innerHTML = this.response;
		   }
		}
		req.send();
	}
	</script>
  </body>
</html>